<?php

class DbControl extends CommonControl {

      function index() {
            $db=M("stu");
            $data=$db->select();            
            $this->assign("data", $data);
            $this->display("index.html");
      }
      //删除
      function del(){
            $sid=  intval($_GET['sid']);
            if($sid){
                  $db=M("stu");
                  $db->where("sid=$sid")->del();
                  $this->success("删除掉成功",__WEB__."?c=db");
            }
      }
      function edit(){            
            if(isset($_POST['sname'])){
                  $db=M('stu');
                  $db->update();
                  $this->success("修改成功",__WEB__."?c=db");
            }  else {
                  $sid=  intval($_GET['sid']);
                  if($sid){
                        $db=M('stu');
                        $field=$db->where("sid=$sid")->select();
                        $this->assign("field", $field[0]);
                        $this->display("edit.html");                          
                  }
            }
      }


      //添加数据
      function add() {
            if (isset($_POST['sname'])) {
                  $db = M("stu");
                  $insertId = $db->insert();
                  $this->success("添加成功",__WEB__."?c=db");
            } else {
                  $this->display("add.html");
            }
      }

}

?>
 